<html>
<head>

<!-- Ext Files -->
<link rel="stylesheet" type="text/css" href="javascript/resources/css/ext-all.css" />
<script type="text/javascript" src="javascript/adapter/ext/ext-base.js"></script>
<script type="text/javascript" src="javascript/ext-all.js"></script>

<script>
Ext.onReady(function(){

    Ext.QuickTips.init();

    // turn on validation errors beside the field globally
    Ext.form.Field.prototype.msgTarget = 'side';

    var bd = Ext.getBody();

    /*
     * ================  Simple form  =======================
     */
    bd.createChild({tag: 'h2', html: 'Form 1 - Very Simple'});

    var store = new Ext.data.JsonStore({ url: 'getform.php?dsn_id=1&database=gracenote&table=content_container' });
    
    //simple.add({fieldLabel: 'Company2', name: 'company2', xtype: 'textarea'});
    
    store.load({
                    callback:   function(record, options, success) {
                                    var form_items  =   [];
                                    
                                    for(index in record) {
                                        
                                        form_items[index]   =   {};
                                        
                                        for(key in record[index].data) {
                                            console.log(key);
                                            form_items[index][key]  =   record[index].data[key];
                                            //console.log('key: ' + key + ' value: ' + record[index].data[key]);
                                        }
                                        
                                        //simple.add(form_items[index]);
                                    }
                                    
                                    /* formpanel */
                                    var simple = new Ext.FormPanel({
                                        labelWidth: 120, // label settings here cascade unless overridden
                                        labelAlign: 'right',
                                        url:'save-form.php',
                                        frame:false,
                                        bodyStyle:'padding:5px 5px 0',
                                        autoWidth: true,
                                        width: 'auto',
                                        autoHeight: true,
                                        height: 'auto',
                                        //defaults: {width: 230},
                                        defaultType: 'textfield',
                                        loadMask:true,
                                        items: form_items,
                                
                                        buttons: [{
                                            text: 'Save'
                                        },{
                                            text: 'Cancel'
                                        }]
                                    });
                                    
                                    win.add(simple);
                                    win.doLayout();
                                    //console.log(form_items);
                                }
               });
               
    win = new Ext.Window({
        id          : 'formwindow',
        applyTo     : 'hello-win',
        layout      : 'fit',
        title       : 'Jomamas cheeseburger ass',
        width       : 400,
        autoHeight  : true,
        height      : 'auto',
        closeAction : 'hide',
        plain       : true,
        loadMask    : true
        
    });
    
    win.show();
    
    // simple.form.load({
    //     url:'jsonform.php',
    //     method:'GET',
    //     waitMsg:'Loading',
    //     success:function(form, action) {
    //         Ext.MessageBox.alert('Message', 'Loaded OK');
    //     },        	
    //     failure:function(form, action) {
    //         Ext.MessageBox.alert('Message', 'Load failed');
    //     }
    // });

    
    //simple.render();
    
});
</script>
<body>

<div id="hello-win" class="x-hidden">
</div>

</body>
</html>
